#include "common.h"

enum BusMode { MASTER, SLAVE };

class SPI
{
public:
	SPI(BusMode m = MASTER);
	~SPI();

	SPI &	operator << (const char *);
	SPI &	operator << (volatile char);
	SPI & 	operator << (volatile char *);

	bool	Connect();
	char	TxRx(volatile char c);
	void	ReleaseSlave();
	void	SelectSlave(uint8 cs);		// select slave CS
	void	ReleaseMaster();	// give up master and return to slave


private:
	byte	token;
	bool	bHasToken;	
	BusMode	mode;
};
